Skip to content

Added test cases related to database operations - #11

Closed
wu-zhao-min wants to merge 1 commit into
berkeleydb:masterfrom
wu-zhao-min:master
Closed

Added test cases related to database operations#11
wu-zhao-min wants to merge 1 commit into
berkeleydb:masterfrom
wu-zhao-min:master

Conversation

@wu-zhao-min

Copy link
Copy Markdown

Added the processing of boundary conditions for the new database, the complete operation process of cursors, and the test cases for database statistics information.

@gburd gburd left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution, and for thinking about boundary/cursor/stat coverage — that kind of testing is welcome.

Unfortunately I can't merge this as-is: it won't compile. test/c/test_db185.c exercises the DB 1.85 compatibility API (it #includes db_185.h and dbp is the 1.85 DB). That handle is defined in src/dbinc/db_185.in and has only these methods:

typedef struct __db {
    DBTYPE type;
    int (*close)(struct __db *);
    int (*del)(const struct __db *, const DBT *, u_int);
    int (*get)(const struct __db *, const DBT *, DBT *, u_int);
    int (*put)(const struct __db *, DBT *, const DBT *, u_int);
    int (*seq)(const struct __db *, DBT *, DBT *, u_int);
    int (*sync)(const struct __db *, u_int);
    void *internal;
    int (*fd)(const struct __db *);
} DB;

So the new code can't build here:

  • dbp->cursor(...) and dbp->stat(...) — no such members on the 1.85 DB.
  • cursor->c_get/c_put/c_close (DBC), and constants DB_NEXT, DB_SET, DB_KEYFIRST, DB_NOTFOUND, DB_BTREE_STAT/DB_HASH_STAT/DB_RECNO_STAT — these are the modern API, not in db_185.h (the 1.85 API iterates with seq() + R_NEXT/R_FIRST and has no cursors or stat).

A couple of other issues to flag regardless:

  • char large_key[1024*1024] is a 1 MB stack array (stack overflow risk).
  • In test_db_cursor, sprintf((char *)key.data, ...) writes into the buffer returned by c_get, which is owned by Berkeley DB — that's a write into library-owned memory.

Two good ways forward:

  1. Best: add these cursor/stat/boundary tests against the modern API — e.g. a new test/c/ program (or extend one that uses db.h/DB_ENV), where DB->cursor, DBC->get, and DB->stat exist. That's where this coverage belongs.
  2. If you specifically want to extend the 1.85 path, use only get/put/del/seq/sync with the R_* flags, and keep buffers caller-owned.

Happy to review a revised version. Closing for changes, not merging.

@gburd gburd left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution — the intent (boundary conditions, cursor traversal, and stat coverage) is welcome. Unfortunately these additions can't land as written, because test/c/test_db185.c exercises the DB 1.85 compatibility API (dbopen()struct __db), and the new code calls modern DB 4.x/5.x methods that do not exist on the 1.85 handle. From src/dbinc/db_185.in the 1.85 struct __db has exactly: close, del, get, put, seq, sync, fd — no cursor, no stat.

Blocking issues:

  1. dbp->cursor(...) / cursor->c_get/c_put/c_close (won't compile). The 1.85 API has no cursor object; sequential traversal is dbp->seq(dbp, &key, &data, R_FIRST|R_NEXT). DBC and its c_* methods are the modern API and aren't declared in db_185.h.
  2. dbp->stat(...) + DB_BTREE_STAT/DB_HASH_STAT/DB_RECNO_STAT (won't compile). The 1.85 handle has no stat method, and those stat structs belong to the modern API.
  3. __os_free(NULL, statp) — an internal engine symbol; a test in test/c/ must not call __os_*. (Moot once #2 is dropped.)
  4. 1 MB stack array (char large_key[1024*1024]) — this repo's C-test convention forbids large stack arrays (stack overflow risk); use the heap.
  5. sprintf((char *)key.data, ...) after a get/c_get writes into DB-owned memory returned by the previous call — never write into memory Berkeley DB owns; and key.data may be NULL there.
  6. char small_key[1] = "" can't hold the terminating NUL; and DB error codes are returned directly (don't strerror(errno) on them).

Suggested path: retarget this coverage at the modern API — the existing test/tcl suite (e.g. test001 for put/get/boundary, cursor tests, statprint001 for stat) already covers most of it, or add a C driver under test/c/ that opens a real DB_ENV/DB handle. If you specifically want 1.85-compat coverage, use seq() (there's no cursor/stat in 1.85). Happy to point at the right harness. Closing for now since it can't compile against the 1.85 header; please reopen a retargeted version.

@gburd gburd closed this Jul 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants